package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFill;
import com.sky.entity.SetmealDish;
import com.sky.enumclass.OperationType;
import com.sky.entity.Setmeal;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author Morpeko
 * @description 针对表【setmeal(套餐)】的数据库操作Mapper
 * @createDate 2024-08-08 20:26:33
 * @Entity com.sky.pojo.Setmeal
 */
@Mapper
public interface SetmealMapper {
    /**
     * 条件分页查询套餐信息
     *
     * @param setmealPageQueryDTO
     * @return
     */
//    @Select("SELECT id, category_id, name, price, status, description, image, create_time, update_time, create_user, update_user" +
//            " FROM setmeal WHERE name like concat('%',#{name},'%') AND status = #{status} and category_id = #{categoryId}" +
//            " ORDER BY create_time DESC")
    Page<SetmealVO> pageQuerySetmeal(Setmeal setmeal);

    @AutoFill(operationType = OperationType.INSERT)
//    @Insert("INSERT INTO setmeal (category_id, name, price, status, description, image, create_time, update_time, create_user, update_user)" +
//            "VALUES " +
//            "(#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void insertSetmeal(Setmeal setmeal);

    @Insert("INSERT INTO setmeal_dish (setmeal_id, dish_id, name, price, copies) VALUES (#{setmealId}, #{dishId}, #{name}, #{price}, #{copies})")
    void insertSetmealDish(SetmealDish setmealDish);

    void deleteSetmeal(List<Long> ids);

    /**
     * 根据ID查询起售状态的套餐信息
     * @param ids
     */
   List<Setmeal> selectOnSetmealByIds(List<Long> ids);

    /**
     * 根据套餐id删除套餐果蔬信息
     * @param ids
     */
    void deleteSetmealDish(List<Long> ids);

    /**
     * 根据套餐id修改套餐状态
     * @param status
     * @param id
     */

    @Update("update setmeal set status = #{status} where id = #{id}")
    void updateSetmealStatus(Integer status, Long id);
    /**
     * 根据ID查询套餐信息
     * @param id
     * @return
     */
    @Select("SELECT id, category_id, name, price, status, description, image, create_time, update_time, create_user, update_user FROM setmeal WHERE id = #{id}")
    Setmeal selectSetmealById(Long id);

    /**
     * 修改套餐信息
     * @param setmeal
     */
    @AutoFill(operationType = OperationType.UPDATE)
//    @Update("UPDATE setmeal SET name = #{name}, price = #{price}, description = #{description}, image = #{image}, update_time = #{updateTime}, update_user = #{updateUser} WHERE id = #{id}")
    void updateSetmeal(Setmeal setmeal);


    /**
     * 根据套餐id查询果蔬选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);


//    @Select("SELECT id, category_id, name, price, status, description, image, create_time, update_time, create_user, update_user FROM setmeal WHERE category_id = #{categoryId}")
//    List<Setmeal> list(Setmeal setmeal);

    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> listForSetmeal(Setmeal setmeal);

    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}




